package cn.sample.common.result;

import lombok.Builder;
import lombok.Data;

/**
 * <h2></h2>
 *
 * <p>统一系统 JSON 返回格式</p>
 *
 * @author HKD
 */
@Data
@Builder
public class JsonResult {

    //状态码
    private Integer code;
    //返回消息
    private String message;
    //返回数据
    private Object data;

    public static JsonResult result(Integer code,String message,Object data){
        return JsonResult.builder()
                .code(code)
                .message(message)
                .data(data)
                .build();
    }

    public static JsonResult result(ResultCode resultCode,Object data){
        return JsonResult.builder()
                .code(resultCode.getCode())
                .message(resultCode.getMessage())
                .data(data)
                .build();
    }

    public static JsonResult ok(Object data){
        return result(ResultCode.SUCCESS,data);
    }

    public static JsonResult ok(){
        return result(ResultCode.SUCCESS,null);
    }

    public static JsonResult error(Object data){
        return result(ResultCode.ERROR,data);
    }

    public static JsonResult error(){
        return result(ResultCode.ERROR,null);
    }

    public static JsonResult error(String message){
        return result(ResultCode.ERROR.getCode(),message,null);
    }


}
